#include<stdio.h>
struct op{
	int a;
	int value;
};

int main(){
	int n,b,c;
	scanf("%d",&n);
	int p[n];
	op operate[n];
	for(b=0;b<n;){
		scanf("%d",&operate[b].a);
		if(operate[b].a==1){scanf("%d",&operate[b].value);};
		b++;
		
	};
	c=0;
	for(b=0;b<n;b++){
		if(operate[b].a==1){
			p[c]=operate[b].value;
			c++;			
		};
		if(operate[b].a==0){
			if(c==0){printf("invalid\n");}
			if(c>0){printf("%d\n",p[c-1]);c--;}
		};
	};
	return 0;
}